package com.sunbeam.service.impl;

import com.sunbeam.dao.UserDao;
import com.sunbeam.dao.impl.UserDaoImpl;
import com.sunbeam.domain.User;
import com.sunbeam.exception.UserIsExistException;
import com.sunbeam.service.LoginService;
import com.sunbeam.utils.ServiceUtils;

/**
 * @Title: LoginService.java
 * @Package com.sunbeam.service.impl
 * @Description: TODO
 * @author lyz lyzpoq_gmail_com
 * @date 2014/02/11 13:18:07
 * @version V1.0
 */
public class LoginServiceImpl implements LoginService {
	private static UserDao dao=new UserDaoImpl();
	
	/**
	 * 
	 * @Title: register
	 * @Description: TODO
	 * @param @param user
	 * @param @throws UserIsExistException
	 * @return void
	 * @throws
	 */
	@Override
	public void register(User user) throws UserIsExistException{	
		boolean b=dao.find(user.getUsername());
		if(b){
			throw new UserIsExistException("该用户名已存在！");
		}
		user.setPassword(ServiceUtils.md5(user.getPassword()));
		dao.add(user);
	}
	
	/**
	 * 
	 * @Title: login
	 * @Description: TODO
	 * @param @param username
	 * @param @param password
	 * @param @return
	 * @return User
	 * @throws
	 */
	@Override
	public User login(String username,String password){
		return dao.find(username,ServiceUtils.md5(password));
	}

}

